package com.tianji.coupon.enums;

public enum Code {
    //系统状态码
    ReqSuccess(1, "执行成功"),
    ReqNotData(2, "没有记录"),
    ReqLostParams(3, "参数为空或不完整"),
    ReqFailure(4, "执行失败"),
    ReqIsExist(5, "已存在相同的记录"),
    ReqErrorParams(6, "参数异常"),
    ReqErrorCheck(7, "参数校验异常"),
    RecordExpire(8, "记录已过期"),

    //用户和接口权限状态码
    ApiNotLogin(401, "用户未登录"),
    ApiForbidden(403, "请求被禁止"),
    ApiNotFound(404, "API接口不存在"),
    ApiStop(405, "API已停用"),
    ApiUnavailable(406, "服务不可用"),
    ApiTimeOut(407, "请求超时"),
    ApiNotPermissions(408, "用户权限不足"),
    ApiCallLimited(409, "超过调用次数"),
    ApiInvalidSign(410, "签名错误"),
    ApiInvalidReplay(411, "重复请求"),
    QrCodeUnavailable(412, "二维码不可用"),
    UserSystemLock(413, "用户系统已经锁定"),

    //门店系统错误
    NotCustomer(421, "该用户不是客户"),
    NotStaff(422, "该用户不是业务员"),
    NotEmployee(423, "该用户不是员工"),
    NotOauthUser(424, "该用户不是第三方用户"),

    //常见错误码
    ErrorSystem(500, "系统繁忙，请稍后重试！"),
    ErrorFormat(501, "格式错误"),
    ErrorType(502, "类型错误"),
    ErrorOverLength(503, "超过规定长度"),
    ErrorEmail(504, "邮箱格式错误"),
    ErrorPhone(505, "手机号码格式错误"),
    ErrorImageCodeNeed(506, "需要输入图形验证码"),
    ErrorImageCode(507, "图形验证码错误"),
    ErrorPhoneCode(508, "手机验证码错误"),

    //流量控制错误码
    FlowLimit(510, "您被限流了，请稍后再试！"),
    FlowDegrade(511, "您访问的服务降级了，请稍后再试！"),
    FlowParamLimit(512, "您的访问太频繁，被系统限流了，请稍后再试！"),
    FlowSystemBlock(513, "您被系统限流了，请稍后再试！"),
    FlowAuthority(514, "您未被授权访问此资源，被限流了，请稍后再试！"),

    //业务级别错误码
    SmsOrIPLimited(1101, "号码或ip距离上次发送的消息的时间太短"),
    SmsPhoneDayLimited(1102, "该号码今天的发送记录已经超过最大次数"),
    SmsIpDayLimited(1103, "该ip今天的发送记录已经超过最大次数"),
    CouponDrawLimited(1120, "卡券领取达到上限"),
    CouponTimeOut(1121, "卡券已过期"),
    AttentionPub(1122, "请关注过微信公众号才能抽奖"),

    // 报名活动错误代码
    ActivityRegistration(1111333, "选手已报名")
    ;

    private int code;
    private String msg;

    Code(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Code parse(int code) {
        Code[] values = Code.values();
        for (Code value : values) {
            if (code == value.getCode()) {
                return value;
            }
        }
        return Code.ErrorSystem;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

}

